import type { ComputedRef, Slots } from "vue"
import type { BasicTableProps, FetchParams } from "../types/table"
import { unref, computed } from "vue"
import { isFunction } from "/@/utils/is"

export function useCard(slots: Slots) {
  const getCardMetaSlotKeys: ComputedRef<string[]> = computed(() => {
    const keys = Object.keys(slots)
    return keys.map((item) => (item.startsWith("cardMeta") ? item : null)).filter((item) => !!item) as string[]
  })

  const getCardSlotKeys: ComputedRef<string[]> = computed(() => {
    const keys = Object.keys(slots)
    return keys.map((item) => (item.startsWith("card") ? item : null)).filter((item) => !!item) as string[]
  })

  function replaceCardMetaSlotKey(key: string) {
    if (!key) return ""
    return key?.replace?.(/cardMeta\-/, "") ?? ""
  }
  function replaceCardSlotKey(key: string) {
    if (!key) return ""
    return key?.replace?.(/card\-/, "") ?? ""
  }
  return {
    replaceCardMetaSlotKey,
    replaceCardSlotKey,
    getCardSlotKeys,
    getCardMetaSlotKeys,
  }
}
